﻿using System;
using System.Collections.Generic;
using CkSoftware.GroupMe.Sdk.Core.Dao;
using Newtonsoft.Json;

namespace CkSoftware.GroupMe.Sdk.Groups.Dao
{
	/// <summary>
	/// The DAO for a single GroupMe group.
	/// </summary>
	public class GroupData
	{
		/// <summary>
		/// The DateTime the group was created.
		/// </summary>
		[JsonIgnore]
		public DateTime CreatedAt
		{
			get { return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(CreatedAtSecondsSinceEpoch); }
		}

		/// <summary>
		/// The DateTime the group was created in unix format (seconds since epoch).
		/// </summary>
		[JsonProperty(PropertyName = "created_at")]
		public long CreatedAtSecondsSinceEpoch { get; set; }

		/// <summary>
		/// The UserId of the creator.
		/// </summary>
		[JsonProperty(PropertyName = "creator_user_id")]
		public string CreatorUserId { get; set; }

		/// <summary>
		/// The description text of the group.
		/// </summary>
		[JsonProperty(PropertyName = "description")]
		public string Description { get; set; }

		/// <summary>
		/// The id of the group.
		/// </summary>
		[JsonProperty(PropertyName = "id")]
		public string Id { get; set; }

		/// <summary>
		/// The <see cref="PictureData" /> for the group-avatar.
		/// </summary>
		[JsonIgnore]
		public PictureData Image
		{
			get { return new PictureData {Url = ImageUrl}; }
		}

		/// <summary>
		/// The group avatar image url.
		/// </summary>
		[JsonProperty(PropertyName = "image_url")]
		public string ImageUrl { get; set; }

		/// <summary>
		/// The list of currently active group-members.
		/// </summary>
		[JsonProperty(PropertyName = "members")]
		public IEnumerable<GroupMemberData> Members { get; set; }

		/// <summary>
		/// The message info of the last written group-message.
		/// </summary>
		[JsonProperty(PropertyName = "messages")]
		public GroupMessagesOverviewData Messages { get; set; }

		/// <summary>
		/// The name of the group.
		/// </summary>
		[JsonProperty(PropertyName = "name")]
		public string Name { get; set; }

		/// <summary>
		/// Defines if the group is in office mode.
		/// </summary>
		[JsonProperty(PropertyName = "office_mode")]
		public bool OfficeMode { get; set; }

		/// <summary>
		/// The phone-number of this group (for SMS to group communication).
		/// </summary>
		[JsonProperty(PropertyName = "phone_number")]
		public string PhoneNumber { get; set; }

		/// <summary>
		/// The share url of this group.
		/// </summary>
		[JsonProperty(PropertyName = "share_url")]
		public string ShareUrl { get; set; }

		/// <summary>
		/// OBSOLETE: a type string which is no longer used according to the GroupMe API support.
		/// </summary>
		[JsonProperty(PropertyName = "type")]
		[Obsolete("According the GroupMe API Support, this is a legacy field and can be ignored.")]
		public string Type { get; set; }

		/// <summary>
		/// The DateTime the group was last updated.
		/// </summary>
		[JsonIgnore]
		public DateTime UpdatedAt
		{
			get { return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(UpdatedAtSecondsSinceEpoch); }
		}

		/// <summary>
		/// The DateTime the group was last updated in unix format (seconds since epoch).
		/// </summary>
		[JsonProperty(PropertyName = "updated_at")]
		public long UpdatedAtSecondsSinceEpoch { get; set; }
	}
}